package com.example.demo.Repository;

import com.example.demo.Entity.Like;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface LikeRepository extends JpaRepository<Like, Long> {

    // 根据项目ID和用户ID删除点赞记录
    void deleteByItemIdAndUserId(Long itemId, Long userId);

    // 检查某个项目是否已被特定用户点赞
    @Query("SELECT COUNT(l) > 0 FROM Like l WHERE l.item.id = :itemId AND l.user.id = :userId")
    boolean existsByItemIdAndUserId(@Param("itemId") Long itemId, @Param("userId") Long userId);

    @Query("SELECT COUNT(l) FROM Like l WHERE l.item.id = :itemId")
    int countByItemId(@Param("itemId") Long itemId);

    List<Like> findByItemIdIn(List<Long> itemIds);

    List<Like> findByUser_Id(Long userId);
}